import requests

url = "http://10.106.153.12:3002/v1/chat/completions"
api_key = "sk-NykXx0lml5gnMy6gEe8bA114BbB644C398Ac0d8b5a123d48"
def request_KimiChat(model:str,query: str, temperature=0.3) -> str:
    """
    使用requests库调用Moonshot AI的API与Kimi进行聊天。
    :param query: 用户的查询字符串。
    :param temperature: 用于控制回答的随机性，范围从0到1。
    :return: Kimi的回答。
    """
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {api_key}"
    }
    data = {
        "model":model,
        "messages": [
           # {"role": "system", "content": "你是 Kimi，由 Moonshot AI 提供的人工智能助手。"},
            {"role": "user", "content": query}
        ],
        "temperature": temperature,
        'stream':False
    }# streaming = True False 都行
    try:
        response = requests.post(url, json=data, headers=headers)
        response.raise_for_status()
        completion = response.json()
        print(completion)
        return completion['choices'][0]['message']['content']
    except Exception as e:
        return f"An error occurred: {e}"

if __name__ == "__main__":
    t = "写一个小红书文案，用20岁的女大学生口吻写一个眼镜店探店笔记，力求真实，表达出店里的卖点和细节优势。不要强调跟其他眼镜店类似的服务或设施"
    t = '写一篇绝句，描写程序员'
    request_response = request_KimiChat('deepseek-chat',t,temperature=0.999)
    print(f"request_response:{request_response}")
